package com.zhichat.web.controller;

import com.zhichat.service.UserInfoService;
import com.zhichat.web.api.PageUtils;
import com.zhichat.web.api.R;
import com.zhichat.web.dto.AdminUserQueryDTO;
import com.zhichat.web.vo.AdminUserInfoVO;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * admin后台用户管理
 *
 * @Author: 团长九哥 https://space.bilibili.com/602197686
 * @CreateDate: 2024/11/21 20:51
 */
@Slf4j
@AllArgsConstructor
@RestController
@RequestMapping("/admin/user")
public class AdminUserController {

    private final UserInfoService userInfoService;

    /**
     * 后台用户列表
     */
    @GetMapping("/list")
    public R<PageUtils<AdminUserInfoVO>> userListOfAdmin(@Validated AdminUserQueryDTO adminUserQueryDTO) {
        return R.success(userInfoService.userListOfAdmin(adminUserQueryDTO));
    }

    /**
     * 后台列表操作 - 账号启用/禁用
     */
    @GetMapping("/is_enable")
    public R<String> isEnable(@RequestParam("userId") Long userId, @RequestParam("status") Integer status) {
        return R.status(userInfoService.isEnable(userId, status));
    }

    /**
     * 后台列表操作 - 账号强制下线
     */
    @GetMapping("/forced_offline")
    public R<String> forcedOffline(@RequestParam("userId") Long userId) {
        return R.status(userInfoService.forcedOffline(userId));
    }
}
